package com.example.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.system.UserInfo;
import com.example.dto.User;
import com.example.dto.ExcelExportResponse;
import com.example.dto.UserExportRequest;
import com.example.service.UserService;
import com.example.utils.ExcelExportUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/*
@description:
@ClassName UserServiceImpl
@author chen
@create 2025-06-25 16:23
@Version 1.0
*/
@Service
public class UserServiceImpl implements UserService
{
    @Override
    public List<User> getUserList()
    {
        List<User> list = new ArrayList<>();
        for (int i = 1; i <= 10; i++)
        {
            User user = new User();
            user.setUserId(i);
            user.setUserName("用户名-" + i);
            user.setAge(20 + i);
            user.setAddress("地址-" + i);
            list.add(user);
        }
        return list;
    }

    @Override
    public ExcelExportResponse userExport(UserExportRequest request)
    {
        List<Integer> userIdList = request.getUserIdList();
        List<User> userList;
        if (CollectionUtil.isEmpty(userIdList))
        {
            userList = this.getUserList();
        } else
        {
            userList = this.getUserList(request.getUserIdList());
        }
        return ExcelExportUtils.build(userList, request);
    }


    public List<User> getUserList(List<Integer> userIdList)
    {
        return this.getUserList().stream().filter(item -> userIdList.contains(item.getUserId())).collect(Collectors.toList());
    }
}
